<script type="text/javascript">
var lastPhoto = false;
function silas_showOptions(id) {
    if (lastPhoto) silas_hideOptions(lastPhoto)
    lastPhoto = id

    var div = document.getElementById('options-'+id)
    if (div) div.style.display='block';
    return false;
}
function silas_hideOptions(id) {
    var div = document.getElementById('options-'+id)
    if (div) div.style.display='none';
    
    var e = window.event;
	if (e) {
        e.cancelBubble = true;
    	if (e.stopPropagation) e.stopPropagation();
    }
    return false;
}
function silas_addPhoto(photoUrl, sourceUrl, width, height, title) {
    var h = 
        '<a href="'+photoUrl+'" class="tt-flickr">' +
        '<img src="'+sourceUrl+'" alt="'+title+'" width="'+width+'" height="'+height+'" border="0" />' +
        '</a> '
        
    var win = window.opener ? window.opener : window.dialogArguments;
	if ( !win ) win = top;
	tinyMCE = win.tinyMCE;
	if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
		tinyMCE.selectedInstance.getWin().focus();
		tinyMCE.execCommand('mceInsertContent', false, h);
	} else win.edInsertContent(win.edCanvas, h);

	return false;
}
</script>
<style type="text/css">
#upload-files a.file-link {
    width:75px;
    height:75px;
}
.photo-options {
    position:absolute;
    top:0px;
    left:0px;
    width:125px;
    padding:5px;
    
    background:white;
    opacity:0.9;
    border:1px solid #ccc;
    font-size:10px;
	line-height:12px;
    z-index:10;
    
    display:none;
}
.photo-options div.close {
    position:absolute;
    top:2px;
    right:2px;
}
.alignleft {
    position:relative;
}
#upload-content {
    padding-top:10px;
}
</style>
<form method="get" id="photos" action="upload.php">
<input type="hidden" name="tab" value="<?php echo $_GET['tab'];?>" />
<input type="hidden" name="post_id" value="<?php echo $_GET['post_id'];?>" />
<input type="hidden" name="action" value="<?php echo $_GET['action'];?>" />
<input type="hidden" name="style" value="<?php echo $_GET['style'];?>" />
<input type="hidden" name="_wpnonce" value="<?php echo $_GET['_wpnonce'];?>" />
<input type="hidden" name="ID" value="<?php echo $_GET['ID'];?>" />

Tags: <input type="text" name="tags" value="<?php echo $tags?>" size="30" />
<input type="radio" name="everyone" value="" <?php echo (!$everyone ? 'checked="checked"' : '')?> id="showmine" /><label for="showmine"> My Photos </label> &nbsp;
<input type="radio" name="everyone" value="1" <?php echo ($everyone ? 'checked="checked"' : '')?> id="showeveryone" /><label for="showeveryone"> Everyone </label>
&nbsp; &nbsp; 
<input type="submit" name="refresh" value="refresh" />
<input type="button" value="upload" onclick="window.open('http://flickr.com/photos/upload/')"/>
<!-- prolly should add a license field -->
</form>
<?php if (count($photos) == 0):?>
Sorry, no photos found!
<?php elseif (is_array($photos)):
$baseurl = get_option('silas_flickr_baseurl');
$linkoptions = get_option('silas_flickr_linkoptions');
$parts = parse_url(get_bloginfo('home'));
$home = 'http://'.$parts['host'];
?>
<ul id='upload-files'>
<?php
$id = 0;
foreach ($photos as $photo):
if ($baseurl && !$everyone && ($linkoptions != 'flickr')) {
    $photoURL = $home.$baseurl.'photo/'.$photo['id'].'/'.$photo['pagename'];
} else {
    $photoURL = array_pop($photo['info']['urls']['url'][0]);
}
?>
<li id='flickr-photo-<?php echo $id?>' class='alignleft'>
<a id='file-link-3' href='<?php echo $photoURL?>' title='<?php echo htmlentities($photo['title']);?>' class='file-link image' onclick="return silas_showOptions(<?php echo $id?>);"><img 
    id="image<?php echo $photo['id']?>" src="<?php echo $photo['sizes']['Square']['source']?>" alt="<?php echo htmlentities($photo['title']);?>" height="<?php echo $photo['sizes']['Square']['height']?>" width="<?php echo $photo['sizes']['Square']['width']?>" border="0" /></a>
    <div class="photo-options" id="options-<?php echo $id?>">
    <?php foreach ($photo['sizes'] as $k => $size):?>
        <a href="<?php echo $size['source']?>" onclick="return silas_addPhoto('<?php echo $photoURL?>', this, '<?php echo $size['width']?>', '<?php echo $size['height']?>', '<?php echo addslashes(htmlentities($photo['title']));?>')"><?php echo $k?><span class="props"> (<?php echo $size['width']?>x<?php echo $size['height']?>)</span></a><br />
    <?php endforeach;?>
    <div class="close"><a href="#" onclick="return silas_hideOptions(<?php echo $id?>);">close</a></div>
    </div>

</li>
<?php 
$id++;
endforeach;?>
</ul>

<?php endif; ?>
